<?php
/**
 * Created by PhpStorm.
 * User: hgq
 * Date: 16/6/14
 * Time: 下午1:23
 */
use yii\helpers\Url;

$web = Url::base();
$this->title = '机构商品池';
?>
<script type="text/javascript" src="<?= $web ?>/js/jquery.tooltips.js"></script>
<script type="application/javascript">

    var importGoodsList = new Array();

    $(function ($) {
//        var response_institution_code = <?//=json_encode($institution_code)?>//;
//        var data = {};//获取机构列表（不包括0机构）
//        var re = requestJson("<?//=Url::to(["goods/get-all-institution"])?>//", data);
//        if (re.status == 0) {
//            var inst = re.data.instlist;
//            if (inst != false) {
//                $.each(inst, function (i, item) {
//                    if (response_institution_code != null && item.code == response_institution_code) {
//                        $("#institution").append("<option  value='" + item.code + "' selected='selected'>" + item.name + "</option>");
//                    } else {
//                        $("#institution").append("<option  value='" + item.code + "'>" + item.name + "</option>");
//                    }
//                });
//            }
//        }
//
//        //设置机构是否可选择
//        var currentManager = <?//=json_encode(\app\models\Manager::getCurrentManager()) ?>//;
//        var current_institution_code = currentManager.institution_code;
//        if (current_institution_code != null && current_institution_code != '' && current_institution_code != '0') {
//            $("#institution").attr("disabled", "disabled");
//        }

        //设置机构是否可选择
        var currentManager = <?=json_encode(\app\models\Manager::getCurrentManager()) ?>;
        var current_institution_code = currentManager.institution_code;
        if (current_institution_code != null && current_institution_code != '' && current_institution_code != '0') {
            $("#searchInstitution").attr("disabled", "disabled");
        }

        //选择框 全选 全消
        var isChkAllClick = false;
        $('#chkAll').on('ifClicked', function (event) {
            isChkAllClick = true;
        });

        $('#chkAll').on('ifChecked ifUnchecked', function (event) {
            if (isChkAllClick == false) {
                return;
            }
            if (event.type == 'ifChecked') {
                $('input:checkbox[name=goodslist]').iCheck('check');
            } else {
                $('input:checkbox[name=goodslist]').iCheck('uncheck');
            }

            isChkAllClick = false;
        });

        var isItemClick = false;
        $('input:checkbox[name=goodslist]').on('ifClicked', function (event) {
            isItemClick = true;
        });
        $('input:checkbox[name=goodslist]').on('ifChecked ifUnchecked', function (event) {
            if (isItemClick == false) {
                return;
            }
            if ($('input:checkbox[name=goodslist]:checked').length == $('input:checkbox[name=goodslist]').length) {
                $('#chkAll').iCheck('check');
            } else {
                $('#chkAll').iCheck('uncheck');
            }
            isItemClick = false;
        });

    });

    function checkSelectedInst() {
        var institution_code = $("#searchInstitution").val();
        if (institution_code == null || institution_code == '' || institution_code == '0') {
            $("#err_message").text('请选择机构！');
            $("#errMessageModal").modal('show');
            return false;
        } else {
            return true;
        }
    }
    //同步产品(同步上级机构产品)
    function synInstGoods() {
        var institution_code = $("#searchInstitution").val();
        if (!this.checkSelectedInst()) return;
        var data = {};
        data.institution_code = institution_code;
        loading.show();
        requestJson("syn-instgoods-handler", data, true, function (response) {
            loading.hide();
            if (response.status == 0) {
                refresh();
                $("#hint_message").text('操作成功！');
            } else {
                $("#hint_message").text(response.message);
            }
            $("#hintMessageModal").modal('show');
        });

    }

    function refresh() {
        var institution_code = $("#searchInstitution").val();
        var href = window.location.href;
        href = removeUrlAllParams(href);
        href = setUrlParam(href, 'page', 1);
        if (institution_code != '' && institution_code != null) {
            href = setUrlParam(href, 'inst', institution_code);
        }
        window.location.href = href;
    }

    function refreshthis() {
        var href = window.location.href;
        window.location.href = href;
    }

    //筛选
    function filter(filtertype) {
//        if (!this.checkSelectedInst()) return;//20170116 去掉机构筛选条件
        var code = '';
        var name = '';
        var group_code = '';
        var group_item_name = '';
        var brand = '';
        var type = '';
        var is_enabled = '';
        var is_shelved = '';
        var is_newest = '';
        var is_hot = '';
        var is_top = '';
        var is_activity = '';
        var is_trusteeship = '';
        var is_pcr = '';
        var jsjg_form = '';
        var jsjg_to = '';
        var jgdb1 = '';
        var jgdb2 = '';
        var jgdb3 = '';
        var institution_code = '';
        institution_code = $("#searchInstitution").val();
        if (filtertype == 1) {
            code = $("#head_code").val();
            name = $("#head_name").val();
            is_enabled = $("#head_is_enabled").val();
            is_shelved = $("#head_is_shelved").val();
        } else {
            code = $("#dlg_code").val();
            name = $("#dlg_name").val();
            group_code = $("#dlg_group_code").val();
            group_item_name = $("#dlg_group_item_name").val();
            brand = $("#dlg_brand").val();
            type = $("#dlg_type").val();
            is_enabled = $("#dlg_is_enabled").val();
            is_shelved = $("#dlg_is_shelved").val();
            is_newest = $("#dlg_is_newest").val();
            is_hot = $("#dlg_is_hot").val();
            is_top = $("#dlg_is_top").val();
            is_activity = $("#dlg_is_activity").val();
            is_trusteeship = $("#dlg_is_trusteeship").val();
            if ($("#is_pcr").is(':checked') == true) {
                is_pcr = 1;
            }
            jsjg_form = $("#dlg_jsjg_form").val();
            jsjg_to = $("#dlg_jsjg_to").val();
            jgdb1 = $("#dlg_jgdb1").val();
            jgdb2 = $("#dlg_jgdb2").val();
            jgdb3 = $("#dlg_jgdb3").val();
        }

        var href = window.location.href;
        href = removeUrlAllParams(href);
        href = setUrlParam(href, 'page', 1);
        if (institution_code != '' && institution_code != null) {
            href = setUrlParam(href, 'inst', institution_code);
        }
        if (code != '' && code != null) {
            href = setUrlParam(href, 'code', code);
        }
        if (name != '' && name != null) {
            href = setUrlParam(href, 'name', name);
        }
        if (group_code != '' && group_code != null) {
            href = setUrlParam(href, 'group_code', group_code);
        }
        if (group_item_name != '' && group_item_name != null) {
            href = setUrlParam(href, 'group_item_name', group_item_name);
        }
        if (brand != '' && brand != null) {
            href = setUrlParam(href, 'brand', brand);
        }
        if (type != '' && type != null) {
            href = setUrlParam(href, 'type', type);
        }
        if (is_enabled != '' && is_enabled != null) {
            href = setUrlParam(href, 'enabled', is_enabled);
        }
        if (is_shelved != '' && is_shelved != null) {
            href = setUrlParam(href, 'shelved', is_shelved);
        }
        if (is_newest != '' && is_newest != null) {
            href = setUrlParam(href, 'newest', is_newest);
        }
        if (is_hot != '' && is_hot != null) {
            href = setUrlParam(href, 'hot', is_hot);
        }
        if (is_top != '' && is_top != null) {
            href = setUrlParam(href, 'top', is_top);
        }
        if (is_activity != '' && is_activity != null) {
            href = setUrlParam(href, 'activity', is_activity);
        }
        if (is_trusteeship != '' && is_trusteeship != null) {
            href = setUrlParam(href, 'trusteeship', is_trusteeship);
        }
        if (is_pcr != '' && is_pcr != null) {
            href = setUrlParam(href, 'is_pcr', is_pcr);
        }
        if (jsjg_form != '' && jsjg_form != null) {
            href = setUrlParam(href, 'jsjg_form', jsjg_form);
        }
        if (jsjg_to != '' && jsjg_to != null) {
            href = setUrlParam(href, 'jsjg_to', jsjg_to);
        }
        if (jgdb1 != '' && jgdb1 != null && jgdb1 != -1) {
            href = setUrlParam(href, 'jgdb1', jgdb1);
        }
        if (jgdb2 != '' && jgdb2 != null && jgdb2 != -1) {
            href = setUrlParam(href, 'jgdb2', jgdb2);
        }
        if (jgdb3 != '' && jgdb3 != null && jgdb3 != -1) {
            href = setUrlParam(href, 'jgdb3', jgdb3);
        }

        window.location.href = href;
    }

    //高级查询
    function modalFilter() {
//        if (!this.checkSelectedInst()) return;
        $('#myModalFilter').modal('show');
    }

    //导入
    function importClick() {
        if (!this.checkSelectedInst()) return;

        $("#import_file_error").html('');
        $("#import_goods_list").html('');
        $("#upload_file").val('');
        var institution_code = $("#searchInstitution").val();
        $("#upload_institution_code").val(institution_code);

        $('#myModalInstGoodsImport').modal('show');
    }

    //导入文件
    function importFile() {
        $("#import_file_error").html('');
        $("#import_goods_list").html('');
        loading.show();
        importGoodsList = new Array();
        if ($("#upload_file").val() != '') {
            $("#upload_file_submit_form").submit();
            $ex1 = 0;
            $("#upload_exec_target").load(function () {
                if ($ex1 == 0) {
                    try {
                        var result = eval('(' + ($("#upload_exec_target").contents().find("body").html()) + ')');

                        if (result.status == 0) {

                            importGoodsList = [];
                            var goods = {};
                            if (result.data != null && result.data != '') {
                                var re = result.data.goods_list;
                                $.each(re, function (i, item) {
                                    goods = {};
                                    goods.goods_code = '';
                                    goods.goods_name = '';
                                    goods.settlement_price = 0;
                                    goods.selling_price = 0;
                                    goods.supply_price = 0;
                                    if (item.goods_code != null && item.goods_code != '') {
                                        goods.goods_code = item.goods_code;
                                    }
                                    if (item.goods_name != null && item.goods_name != '') {
                                        goods.goods_name = item.goods_name;
                                    }
                                    if (item.settlement_price != null && item.settlement_price != '') {
                                        goods.settlement_price = item.settlement_price;
                                    }
                                    if (item.selling_price != null && item.selling_price != '') {
                                        goods.selling_price = item.selling_price;
                                    }
                                    if (item.supply_price != null && item.supply_price != '') {
                                        goods.supply_price = item.supply_price;
                                    }
                                    if (item.is_enabled != null && item.is_enabled == '是') {
                                        goods.is_enabled = 1;
                                    } else {
                                        goods.is_enabled = 0;
                                    }
                                    if (item.is_shelved != null && item.is_shelved == '是') {
                                        goods.is_shelved = 1;
                                    } else {
                                        goods.is_shelved = 0;
                                    }
                                    if (item.is_newest != null && item.is_newest == '是') {
                                        goods.is_newest = 1;
                                    } else {
                                        goods.is_newest = 0;
                                    }
                                    if (item.is_hot != null && item.is_hot == '是') {
                                        goods.is_hot = 1;
                                    } else {
                                        goods.is_hot = 0;
                                    }
                                    if (item.is_top != null && item.is_top == '是') {
                                        goods.is_top = 1;
                                    } else {
                                        goods.is_top = 0;
                                    }
                                    if (item.is_show != null && item.is_show == '是') {
                                        goods.is_show = 1;
                                    } else {
                                        goods.is_show = 0;
                                    }
                                    goods.error = item.error;
                                    importGoodsList[i] = goods;
                                    if (item.error != null && item.error != '') {
                                        $("#import_goods_list").append("<tr><td>" + goods.goods_code + "</td><td>" + goods.goods_name + "</td><td>" + goods.settlement_price + "</td><td>" + goods.selling_price + "</td><td>" + goods.supply_price + "</td><td>" + item.is_enabled + "</td><td>" + item.is_shelved + "</td><td>" + item.is_newest + "</td><td>" + item.is_hot + "</td><td>" + item.is_top + "</td><td>" + item.is_show + "</td><td><span class=\"label label-danger\" onclick=\"errClick('" + goods.error + "')\">ERR</span></td></tr>");
                                    } else {
                                        $("#import_goods_list").append("<tr><td>" + goods.goods_code + "</td><td>" + goods.goods_name + "</td><td>" + goods.settlement_price + "</td><td>" + goods.selling_price + "</td><td>" + goods.supply_price + "</td><td>" + item.is_enabled + "</td><td>" + item.is_shelved + "</td><td>" + item.is_newest + "</td><td>" + item.is_hot + "</td><td>" + item.is_top + "</td><td>" + item.is_show + "</td><td></td></tr>");
                                    }
                                });
                            }

                        } else {
                            var re = eval('(' + result.message + ')');
                            $("#import_file_error").html(re);
                        }

                    } catch (err) {
                        var re = "网络异常，请重试";
                        $("#import_file_error").html(re + err.message);
                    }

                    loading.hide();
                    $ex1 = 1;
                }
            });
        }
    }

    // 错误信息查看
    function errClick(dcm) {
        $("#err_message").html(dcm);
        $("#errMessageModal").modal('show');
    }

    // 确认导入
    function importConfirm() {
        if (importGoodsList == null || importGoodsList == '' || importGoodsList.length <= 0) {
            $("#err_message").html("请选择需要导入的数据！");
            $("#errMessageModal").modal('show');
            return;
        }
        $isExistsErr = 0;
        for (var i = 0; i < importGoodsList.length; i++) {
            if (importGoodsList[i].error != null && importGoodsList[i].error != '') {
                $isExistsErr = 1;
            }
        }
        if ($isExistsErr == 1) {
            $("#err_message").html("导入的表格中存在错误数据，请修改相关内容后重新导入！");
            $("#errMessageModal").modal('show');
            return;
        }

        var upload_institution_code = $("#upload_institution_code").val();

        loading.show();
        for (var i = 0; i < importGoodsList.length; i++) {
            var goodsList = new Array();
            goodsList[0] = importGoodsList[i];
            var data = {};
            data.institution_code = upload_institution_code;
            data.importGoodsList = goodsList;
            var re = requestJson("import-institution-goods-confirm-handler", data);
            if (re.status == 0) {
                importGoodsList[i].error = 0;
            } else {
                importGoodsList[i].error = 1;
            }
        }

        $("#import_goods_list").html('');
        for (var i = 0; i < importGoodsList.length; i++) {
            var goods_temp = importGoodsList[i];
            var code_temp = goods_temp.goods_code;
            var name_temp = goods_temp.goods_name;
            var settlement_price_temp = goods_temp.settlement_price;
            var selling_price_temp = goods_temp.selling_price;
            var supply_price_temp = goods_temp.supply_price;
            var is_enabled_temp = '';
            var is_shelved_temp = '';
            var is_newest_temp = '';
            var is_hot_temp = '';
            var is_top_temp = '';
            var is_show_temp = '';
            var error_temp = goods_temp.error;

            if (goods_temp.is_enabled != null && goods_temp.is_enabled == 1) {
                is_enabled_temp = '是';
            } else {
                is_enabled_temp = '否';
            }
            if (goods_temp.is_shelved != null && goods_temp.is_shelved == 1) {
                is_shelved_temp = '是';
            } else {
                is_shelved_temp = '否';
            }
            if (goods_temp.is_newest != null && goods_temp.is_newest == 1) {
                is_newest_temp = '是';
            } else {
                is_newest_temp = '否';
            }
            if (goods_temp.is_hot != null && goods_temp.is_hot == 1) {
                is_hot_temp = '是';
            } else {
                is_hot_temp = '否';
            }
            if (goods_temp.is_top != null && goods_temp.is_top == 1) {
                is_top_temp = '是';
            } else {
                is_top_temp = '否';
            }
            if (goods_temp.is_show != null && goods_temp.is_show == 1) {
                is_show_temp = '是';
            } else {
                is_show_temp = '否';
            }
            if (error_temp != null && error_temp == 0) {
                $("#import_goods_list").append("<tr><td>" + code_temp + "</td><td>" + name_temp + "</td><td>" + settlement_price_temp + "</td><td>" + selling_price_temp + "</td><td>" + supply_price_temp + "</td><td>" + is_enabled_temp + "</td><td>" + is_shelved_temp + "</td><td>" + is_newest_temp + "</td><td>" + is_hot_temp + "</td><td>" + is_top_temp + "</td><td>" + is_show_temp + "</td><td>操作成功！</td></tr>");
            } else {
                $("#import_goods_list").append("<tr><td>" + code_temp + "</td><td>" + name_temp + "</td><td>" + settlement_price_temp + "</td><td>" + selling_price_temp + "</td><td>" + supply_price_temp + "</td><td>" + is_enabled_temp + "</td><td>" + is_shelved_temp + "</td><td>" + is_newest_temp + "</td><td>" + is_hot_temp + "</td><td>" + is_top_temp + "</td><td>" + is_show_temp + "</td><td><span class=\"label label-danger\">操作失败！</span></td></tr>");
            }

        }
        loading.hide();
        $("#hint_message").text('操作完成！');
        $("#hintMessageModal").modal('show');
        //由于整个列表提数量大时会提交不过去 改为上面的FOR循环方式
//        var data = {};
//        data.institution_code = upload_institution_code;
//        data.importGoodsList = importGoodsList;
//        var re = requestJson("import-institution-goods-confirm-handler", data);
//        $("#hint_message").text('');
//        if (re.status == 0) {
//            loading.hide();
//            $("#hint_message").text('操作成功！');
//        } else {
//            loading.hide();
//            $("#hint_message").text('操作失败！');
//        }
//        $("#hintMessageModal").modal('show');
    }

    //编辑
    function goodsEdit(goods_code, institution_code) {
        var data = {};
        data.goods_code = goods_code;
        data.institution_code = institution_code;

        $("#goodsdetailedit").html('');
        requestHtml('instgoods-detail-part-edit', data, true, function (responseHtml) {
            $("#goodsdetailedit").html(responseHtml);
        }, function () {
            $("#goodsdetailedit").append('无产品详情数据 ');
        });
    }

    //上架时间编辑事件
    function editIsShelvedOnClick() {
        var is_shelved = $("#edit_is_shelved");//是否上架
        var shelve_datetime_old = $("#edit_shelve_datetime_old").val();//上架时间(原来的旧值)
        var shelve_datetime = $("#edit_shelve_datetime").val();//上架时间
        if (is_shelved.is(':checked') == true) {
            if (shelve_datetime == null || shelve_datetime == '') {
                var myDate = new Date();
                var mytime = myDate.toLocaleTimeString();
                $("#edit_shelve_datetime").val(getNowFormatDate());
            }
        } else {
            $("#edit_shelve_datetime").val(shelve_datetime_old);
        }
    }

    //取得当前时间
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var strHours = date.getHours();
        var strMinutes = date.getMinutes();
        var strSeconds = date.getSeconds();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if (strHours >= 0 && strHours <= 9) {
            strHours = "0" + strHours;
        }
        if (strMinutes >= 0 && strMinutes <= 9) {
            strMinutes = "0" + strMinutes;
        }
        if (strSeconds >= 0 && strSeconds <= 9) {
            strSeconds = "0" + strSeconds;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + strHours + seperator2 + strMinutes + seperator2 + strSeconds;
        return currentdate;
    }

    //保存机构产品信息
    function goodsEditSave() {
        var institution_code = $("#edit_institution_code").val();//机构编码
        var goods_code = $("#edit_code").val();//商品编码
        var settlement_price = $("#edit_settlement_price").val();//结算价格
        var selling_price = $("#edit_selling_price").val();//销售价格
        var supply_price = $("#edit_supply_price").val();//供应价格
        var is_enabled = $("#edit_is_enabled");//是否启用
        var is_shelved = $("#edit_is_shelved");//是否上架
        var shelve_datetime = $("#edit_shelve_datetime").val();//上架时间
        var is_newest = $("#edit_is_newest");//是否新品
        var is_hot = $("#edit_is_hot");//是否热销
        var is_top = $("#edit_is_top");//是否置顶
        var is_show = $("#edit_is_show");//是否显示
        var category_code = $("#edit_category").val();//分类编码

        loading.show();
        var data = {};
        data.institution_code = institution_code;
        data.goods_code = goods_code;
        data.settlement_price = settlement_price;
        data.selling_price = selling_price;
        data.supply_price = supply_price;
        data.category_code = category_code;
        if (is_enabled.is(':checked') == true) {
            data.is_enabled = 1;
        } else {
            data.is_enabled = 0;
        }
        if (is_shelved.is(':checked') == true) {
            data.is_shelved = 1;
        } else {
            data.is_shelved = 0;
        }
        data.shelve_datetime = shelve_datetime;
        if (is_newest.is(':checked') == true) {
            data.is_newest = 1;
        } else {
            data.is_newest = 0;
        }
        if (is_hot.is(':checked') == true) {
            data.is_hot = 1;
        } else {
            data.is_hot = 0;
        }
        if (is_top.is(':checked') == true) {
            data.is_top = 1;
        } else {
            data.is_top = 0;
        }
        if (is_show.is(':checked') == true) {
            data.is_show = 1;
        } else {
            data.is_show = 0;
        }

        var re = requestJson("update-inst-goods-handler", data);
        $("#hint_message").text('');
        loading.hide();
        if (re.status == 0) {
            $("#myModalGoodsDetailEdit").modal('hide');
            refreshthis();
        } else {
            $("#hint_message").text('操作失败：' + re.message);
            $("#hintMessageModal").modal('show');
        }

    }

    //展示产品详细信息
    function show_goods_detail(goods_code, institution_code) {
        goods_code = encodeURI(goods_code);
        var data = {};
        data.goods_code = goods_code;
        data.institution_code = institution_code;

        $("#goodsdetail").html('');
        requestHtml('instgoods-detail-part-view', data, true, function (responseHtml) {
            $("#goodsdetail").html(responseHtml);
        }, function () {
            $("#goodsdetail").html('无产品详情数据!');
        });
    }

    //展示产品HTML详细信息
    function show_html_detail(goods_code, institution_code) {
        goods_code = encodeURI(goods_code);
        var data = {};
        data.goods_code = goods_code;
        data.institution_code = institution_code;

        $("#htmldetail").html('');
        requestHtml('goods-htmldetail-part-view', data, true, function (responseHtml) {
            $("#htmldetail").html(responseHtml);
        }, function () {
            $("#htmldetail").html('无产品详情数据!');
        });
    }

    // 全部上下架
    function shelve(is_shelved) {
        if (!this.checkSelectedInst()) return;

        shelvGgoodsCodeList = new Array();//全部上下架时初始货选择上下架的产品列表

        var institution_code = $("#searchInstitution").val();
        var hitmsg = "";
        if (is_shelved == 1) {
            hitmsg = "是否确认将机构【" + institution_code + "】所有未上架的产品全部上架？";
        } else {
            hitmsg = "是否确认将机构【" + institution_code + "】所有已上架的产品全部下架？";
        }
        $("#shelve_inst_code").val(institution_code);
        $("#shelve_is_shelved").val(is_shelved);
        $("#shelve_modal_body").html(hitmsg);
        $('#shelveModal').modal('show');
    }

    //确定全部上下架
    function confShelve() {
        var oper_institution_code = $("#shelve_inst_code").val();
        var oper_is_shelved = $("#shelve_is_shelved").val();
        $("#shelveModal").modal('hide');

        var data = {};
        data.institution_code = oper_institution_code;
        data.is_shelved = oper_is_shelved;
        data.goods_code_list = shelvGgoodsCodeList;

        loading.show();
        requestJson("institution-goods-shelve-handler", data, true, function (response) {
            loading.hide();
            if (response.status == 0) {
                refreshthis();
            } else {
                $("#hint_message").text(response.message);
                $("#hintMessageModal").modal('show');
            }
        });
    }

    //取消全部上下架
    function cancShelve() {
        $("#shelve_inst_code").val('');
        $("#shelve_is_shelved").val('');
        $("#shelveModal").modal('hide');
    }
    var shelvGgoodsCodeList = new Array();

    // 批量上下架
    function shelveSelected(is_shelved) {
        var hitmsg = "";
        if (is_shelved == 1) {
            hitmsg = "上架";
        } else {
            hitmsg = "下架";
        }
        shelvGgoodsCodeList = new Array();
        var institutionCodeList = [];
        $("input:checkbox[name=goodslist]:checked").each(function () {
            shelvGgoodsCodeList.push($(this).data('goods-code'));
            institutionCodeList.push($(this).data('institution-code'));
        });

        var institution_code = institutionCodeList[0];//从选择的数据中取一个机构编号即可  从这里取是为了避免操作错误  直接从选择的数据中取得所属机构保证数据不出错

        if (shelvGgoodsCodeList == null || shelvGgoodsCodeList == '') {
            $("#hint_message").text("请选择需要" + hitmsg + "的产品！");
            $("#hintMessageModal").modal('show');
        } else {
            $("#shelve_inst_code").val(institution_code);
            $("#shelve_is_shelved").val(is_shelved);
            $("#shelve_modal_body").html("是否确认批量" + hitmsg + "这些产品?");
            $('#shelveModal').modal('show');
        }

    }

    // 批量启禁用
    var enabledGgoodsCodeList = new Array();
    function enabledSelected(is_enabled) {
        var hitmsg = "";
        if (is_enabled == 1) {
            hitmsg = "启用";
        } else {
            hitmsg = "禁用";
        }
        enabledGgoodsCodeList = new Array();
        var institutionCodeList = [];
        $("input:checkbox[name=goodslist]:checked").each(function () {
            enabledGgoodsCodeList.push($(this).data('goods-code'));
            institutionCodeList.push($(this).data('institution-code'));
        });

        var institution_code = institutionCodeList[0];//从选择的数据中取一个机构编号即可  从这里取是为了避免操作错误  直接从选择的数据中取得所属机构保证数据不出错

        if (enabledGgoodsCodeList == null || enabledGgoodsCodeList == '') {
            $("#hint_message").text("请选择需要" + hitmsg + "的产品！");
            $("#hintMessageModal").modal('show');
        } else {
            $("#enabled_inst_code").val(institution_code);
            $("#enabled_is_enabled").val(is_enabled);
            $("#enabled_modal_body").html("是否确认批量" + hitmsg + "这些产品?");
            $('#enabledModal').modal('show');
        }

    }
    //确定启禁用
    function confEnabled() {
        var oper_institution_code = $("#enabled_inst_code").val();
        var oper_is_enabled = $("#enabled_is_enabled").val();
        $("#enabledModal").modal('hide');

        var data = {};
        data.institution_code = oper_institution_code;
        data.is_enabled = oper_is_enabled;
        data.goods_code_list = enabledGgoodsCodeList;

        loading.show();
        requestJson("institution-goods-enabled-handler", data, true, function (response) {
            loading.hide();
            if (response.status == 0) {
                if (response.message != null && response.message != '' && response.message != 'success') {
                    $("#hint_message").text(response.message);
                    $("#hintMessageModal").modal('show');
                }
                refreshthis();
            } else {
                $("#hint_message").text(response.message);
                $("#hintMessageModal").modal('show');
            }
        });
    }
    //取消启禁用
    function cancEnabled() {
        $("#enabled_inst_code").val('');
        $("#enabled_is_enabled").val('');
        $("#enabledModal").modal('hide');
    }

    //结算价格变动确认
    function onPriceChangeConfirm(goods_code, institution_code) {
        var data = {};
        data.institution_code = institution_code;
        data.goods_code = goods_code;
        requestJson("inst-goods-price-change-confirm", data, true, function (response) {
            var href = window.location.href;
            window.location.href = href;
        });
    }
    //结算价格变更 查询(处理)
    function onPriceChangeFilter() {

        var institution_code = '';
        institution_code = $("#searchInstitution").val();
        if (!this.checkSelectedInst()) return;

        var href = window.location.href;
        href = removeUrlAllParams(href);
        href = setUrlParam(href, 'page', 1);
        href = setUrlParam(href, 'inst', institution_code);
        href = setUrlParam(href, 'is_pcr', 1);

        window.location.href = href;
    }

    //更新下级机构数据对话框
    function updateChilddata() {
        //取得选择的机构
        var institution_code = $("#searchInstitution").val();
        if (!this.checkSelectedInst()) return;
        updateChildInstData("<?=Url::to(['institution/institution-childlist-part-view'])?>", institution_code, 1);
    }

    //确定更新下级机构数据
    function confUpdateChildData() {
        confUpdateChildInstData("<?=Url::to(['institution/sys-under-institution-data'])?>", 1);
    }


    //设置模态窗 1.当用户点击模态框外部时不会关闭 2.当按下 escape 键时不会关闭 3.当初始化时不显示模态框。
    $(function () {
        $('#myModalGoodsDetailEdit').modal({
            keyboard: false, backdrop: 'static', show: false
        });
        $('#myModalInstGoodsImport').modal({
            keyboard: false, backdrop: 'static', show: false
        });
        $('#shelveModal').modal({
            keyboard: false, backdrop: 'static', show: false
        });
        $('#modalChildInstList').modal({
            keyboard: false, backdrop: 'static', show: false
        });
        $('#myModalFilter').modal({
            keyboard: false, backdrop: 'static', show: false
        });
    });

</script>
<style type="text/css">
    .modal-body {
        overflow: auto;
        max-height: 600px;
    }
</style>
<!-- head filter-->
<div class="panel panel-default">
    <div class="panel-body">
        <div class="form-inline">
            <div class="btn-group">
                <button class="btn btn-primary" type="button" onclick="synInstGoods()"><i class="fa fa-refresh"></i>
                    同步上级机构商品池
                </button>
                <button class="btn btn-primary" type="button" onclick="importClick()"><i class="fa fa-upload"></i> 导入
                </button>
                <button class="btn btn-primary" type="button" onclick="shelve(1)"><i class="fa fa-cog"></i> 全部上架
                </button>
                <button class="btn btn-primary" type="button" onclick="shelve(0)"><i class="fa fa-cog"></i> 全部下架
                </button>
                <button class="btn btn-primary" type="button" onclick="shelveSelected(1)"><i class="fa fa-cog"></i> 批量上架
                </button>
                <button class="btn btn-primary" type="button" onclick="shelveSelected(0)"><i class="fa fa-cog"></i> 批量下架
                </button>
                <button class="btn btn-primary" type="button" onclick="enabledSelected(1)"><i class="fa fa-cog"></i> 批量启用
                </button>
                <button class="btn btn-primary" type="button" onclick="enabledSelected(0)"><i class="fa fa-cog"></i> 批量禁用
                </button>
                <?php if (\app\models\Permission::hasPermission("institution", "sys-under-institution-data")) {
                    ?>
                    <button class="btn btn-primary" type="button" onclick="updateChilddata()"><i class="fa fa-cog"></i>
                        更新下级机构数据
                    </button>
                    <?php
                } ?>
            </div>
        </div>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body">
        <div class="form-inline">
            <div class="pull-right" style=" margin-top: 5px">
                <div class="form-group">
                    <?= app\widgets\InstitutionHierarchyAutocompleteWidget::widget(['id' => 'searchInstitution', 'currentInstitutionCode' => $institution_code, 'defaultText' => '——选择机构——', 'tagSourceType' => 1, 'isShowCustomPrice' => true]) ?>
                </div>
                <div class="form-group">
                    <label class="sr-only" for="exampleInputEmail2">商品编码</label>
                    <input type="text" class="form-control" id="head_code" placeholder="商品编码" value="<?= $code ?>">
                </div>
                <div class="form-group">
                    <label class="sr-only" for="exampleInputPassword2">商品名称</label>
                    <input type="text" class="form-control" id="head_name" placeholder="商品名称" value="<?= $name ?>">
                </div>
                <select id="head_is_enabled" class="form-control" onchange="">
                    <option value="" <?php if ($enabled == "-1") echo "selected=\"selected\""; ?>>是否启用</option>
                    <option value="1" <?php if ($enabled == "1") echo "selected=\"selected\""; ?>>启用</option>
                    <option value="0" <?php if ($enabled == "0") echo "selected=\"selected\""; ?>>禁用</option>
                </select>
                <select id="head_is_shelved" class="form-control" onchange="">
                    <option value="" <?php if ($shelved == "-1") echo "selected=\"selected\""; ?>>是否上架</option>
                    <option value="1" <?php if ($shelved == "1") echo "selected=\"selected\""; ?>>已经上架</option>
                    <option value="0" <?php if ($shelved == "0") echo "selected=\"selected\""; ?>>未上架</option>
                </select>
                <button type="button" class="btn btn-primary" onclick="filter(1)"><i class="fa fa-search"></i> 搜索
                </button>
                <button type="button" class="btn btn-primary" onclick="modalFilter()">
                    高级搜索
                </button>
            </div>
        </div>
    </div>
</div>
<?php if ($pcr != null && $pcr == 1) {
    ?>
    <div class="alert alert-warning">上级机构针对某些商品的【结算价格】做了变更，请尽快处理。<a href="javascript:void(0)"
                                                                    onclick="onPriceChangeFilter()"><i
                class="fa fa-search"></i>去处理</a></div>
    <?php
} ?>
<!-- body table-->
<div class="panel panel-default" id="goodsList">
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <thead class="nowrap">
                <tr>
                    <th style="width: 40px;">
                        <div class="checkbox square-blue">
                            <input type="checkbox" id="chkAll">
                        </div>
                    </th>
                    <th>商品图片</th>
                    <th>商品编码</th>
                    <th>商品名称</th>
                    <th>机构名称</th>
                    <th>结算价格</th>
                    <th>销售价格</th>
                    <th>供应价格</th>
                    <th>是否启用</th>
                    <th>是否上架</th>
                    <th>其它属性</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <?php
                if ($list != null && $list != '') {
                    for ($i = 0; $i < count($list); $i++) {
                        ?>
                        <tr>
                            <td style=" vertical-align:middle;">
                                <div class="checkbox square-blue">
                                    <input type="checkbox" name="goodslist" data-goods-code="<?= $list[$i]['code'] ?>"
                                           data-institution-code="<?= $list[$i]['institution_code'] ?>">
                                </div>
                            </td>
                            <td align="center" style="vertical-align:middle;">
                                <a href="javascript:void(0)" class="tooltips" rel="<?= $list[$i]['goods_image'] ?>"
                                   target="_blank">
                                    <img src="<?= $list[$i]['goods_image'] ?>" style="width: 3rem; height: 3rem;">
                                </a>
                            </td>
                            <td><a href="javascript:void(0)"
                                   onclick="show_goods_detail('<?= $list[$i]['code'] ?>','<?= $list[$i]['institution_code'] ?>')"
                                   data-toggle="modal"
                                   data-target="#myModalGoodsDetail"><?= $list[$i]['code'] ?></a></td>
                            <td><?= $list[$i]['name'] ?></td>
                            <td><?= $list[$i]['institution_name'] ?></td>
                            <td><?= $list[$i]['settlement_price'] ?>
                                <?php if ($list[$i]['ischangesprice'] == 1) {
                                    $hintMsg = "上级机构修改了结算价格:原价" . $list[$i]['supply_price_old'] . " 现价" . $list[$i]['supply_price_new'] . "，请确认！ (请点击感叹号确认)";
                                    ?>
                                    <span
                                        class="btn-clipboard popovers" data-trigger="hover"
                                        data-placement="top"
                                        data-content="<?= $hintMsg ?>"
                                        data-original-title="提示"
                                        onclick="onPriceChangeConfirm('<?= $list[$i]['code'] ?>','<?= $list[$i]['institution_code'] ?>')">
                                        <i class="fa exclamation-sign" style="color: red"></i></span>
                                    <?php
                                } ?>
                            </td>
                            <td><?= $list[$i]['selling_price'] ?></td>
                            <td><?= $list[$i]['supply_price'] ?></td>
                            <td><?php if ($list[$i]["is_enabled"] == 1) {
                                    echo '<span class="label label-success">启用</span>';
                                } else {
                                    echo '<span class="label label-danger">禁用</span>';
                                } ?></td>
                            <td><?php if ($list[$i]["is_shelved"] == 1) {
                                    echo '<span class="label label-success">已经上架</span>';
                                } else {
                                    echo '<span class="label label-default">未上架</span>';
                                } ?></td>
                            <td><?php if ($list[$i]["is_newest"] == 1) {
                                    echo '<span class="label label-default">新品<br/></span>';
                                }
                                if ($list[$i]["is_hot"] == 1) {
                                    echo '<span class="label label-default">热销<br/></span>';
                                }
                                if ($list[$i]["is_top"] == 1) {
                                    echo '<span class="label label-default">置顶<br/></span>';
                                }
                                if ($list[$i]["is_activity"] == 1) {
                                    echo '<span class="label label-default">活动商品</span>';
                                } ?></td>
                            <td>
                                <div class="btn-group">
                                    <button class="btn btn-link btn-xs" type="button"
                                            onclick="show_html_detail('<?= $list[$i]['code'] ?>','<?= $list[$i]['institution_code'] ?>')"
                                            data-toggle="modal"
                                            data-target="#myModalHtmlDetail">
                                        网页详情
                                    </button>
                                    <button class="btn btn-link btn-xs" type="button"
                                            onclick="goodsEdit('<?= $list[$i]['code'] ?>','<?= $list[$i]['institution_code'] ?>')"
                                            data-toggle="modal"
                                            data-target="#myModalGoodsDetailEdit">
                                        编辑
                                    </button>

                                </div>
                            </td>
                        </tr>
                        <?php
                    }
                }
                ?>
                </tbody>
            </table>
        </div>
        <div class="pull-left">
            <?= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
        </div>
    </div>
</div>
<!-- Modal filter-->
<div class="modal fade" id="myModalFilter" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">高级搜索</h4>
            </div>
            <div id="modalFilter" class="modal-body">
                <form class="form-inline" role="form">
                    <div class="form-group">
                        <label for="exampleInputEmail2">商品编码：</label>
                        <input type="text" class="form-control" style="width: 203px;" id="dlg_code" placeholder=""
                               value="<?= $code ?>">

                        <label for="exampleInputPassword2">商品名称：</label>
                        <input type="text" class="form-control" style="width: 203px;" id="dlg_name" placeholder=""
                               value="<?= $name ?>">
                    </div>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">同款编码：</label>
                        <input type="text" class="form-control" style="width: 203px;" id="dlg_group_code" placeholder=""
                               value="<?= $group_code ?>">

                        <label for="exampleInputPassword2">差异名称：</label>
                        <input type="text" class="form-control" style="width: 203px;" id="dlg_group_item_name"
                               placeholder=""
                               value="<?= $group_item_name ?>">
                    </div>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">商品品牌：</label>
                        <input type="text" class="form-control" style="width: 203px;" id="dlg_brand" placeholder=""
                               value="<?= $brand ?>">

                        <label for="exampleInputPassword2">商品类型：</label>
                        <select id="dlg_type" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($type == "") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($type == "1") echo "selected=\"selected\""; ?>>实物</option>
                            <option value="2" <?php if ($type == "2") echo "selected=\"selected\""; ?>>虚拟商品</option>
                        </select>
                    </div>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">是否启用：</label>
                        <select id="dlg_is_enabled" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($enabled == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($enabled == "1") echo "selected=\"selected\""; ?>>启用</option>
                            <option value="0" <?php if ($enabled == "0") echo "selected=\"selected\""; ?>>禁用</option>
                        </select>
                        <label for="exampleInputEmail2">是否上架：</label>
                        <select id="dlg_is_shelved" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($shelved == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($shelved == "1") echo "selected=\"selected\""; ?>>已经上架</option>
                            <option value="0" <?php if ($shelved == "0") echo "selected=\"selected\""; ?>>未上架</option>
                        </select>
                    </div>
                    <br>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">是否新品：</label>
                        <select id="dlg_is_newest" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($newest == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($newest == "1") echo "selected=\"selected\""; ?>>是</option>
                            <option value="0" <?php if ($newest == "0") echo "selected=\"selected\""; ?>>否</option>
                        </select>
                        <label for="exampleInputEmail2">是否热销：</label>
                        <select id="dlg_is_hot" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($hot == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($hot == "1") echo "selected=\"selected\""; ?>>是</option>
                            <option value="0" <?php if ($hot == "0") echo "selected=\"selected\""; ?>>否</option>
                        </select>
                    </div>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">是否置顶：</label>
                        <select id="dlg_is_top" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($top == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($top == "1") echo "selected=\"selected\""; ?>>是</option>
                            <option value="0" <?php if ($top == "0") echo "selected=\"selected\""; ?>>否</option>
                        </select>
                        <label for="exampleInputEmail2">是否活动：</label>
                        <select id="dlg_is_activity" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($activity == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($activity == "1") echo "selected=\"selected\""; ?>>是</option>
                            <option value="0" <?php if ($activity == "0") echo "selected=\"selected\""; ?>>否</option>
                        </select>
                    </div>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">是否托管：</label>
                        <select id="dlg_is_trusteeship" class="form-control" style="width: 203px;" onchange="">
                            <option value="" <?php if ($trusteeship == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($trusteeship == "1") echo "selected=\"selected\""; ?>>是</option>
                            <option value="0" <?php if ($trusteeship == "0") echo "selected=\"selected\""; ?>>否</option>
                        </select>
                    </div>
                    <br>
                    <div class="form-group" style=" margin-top: 10px">
                        <label>
                            <input type="checkbox" id="is_pcr" <?php if ($is_pcr == 1) {
                                echo("checked");
                            } ?>> 结算价格是否有变更
                        </label>
                    </div>
                    <br>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">结算价格</label>
                        <select id="dlg_jgdb1" class="form-control" style="width: 100px;" onchange="">
                            <option value="-1" <?php if ($jgdb1 == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($jgdb1 == "1") echo "selected=\"selected\""; ?>>不等于</option>
                            <option value="2" <?php if ($jgdb1 == "2") echo "selected=\"selected\""; ?>>大于</option>
                            <option value="3" <?php if ($jgdb1 == "3") echo "selected=\"selected\""; ?>>小于</option>
                        </select>
                        <label for="exampleInputEmail2">销售价格</label>
                    </div>
                    <br>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">结算价格</label>
                        <select id="dlg_jgdb2" class="form-control" style="width: 100px;" onchange="">
                            <option value="-1" <?php if ($jgdb2 == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($jgdb2 == "1") echo "selected=\"selected\""; ?>>不等于</option>
                            <option value="2" <?php if ($jgdb2 == "2") echo "selected=\"selected\""; ?>>大于</option>
                            <option value="3" <?php if ($jgdb2 == "3") echo "selected=\"selected\""; ?>>小于</option>
                        </select>
                        <label for="exampleInputEmail2">供应价格</label>
                    </div>
                    <br>
                    <div class="form-group" style=" margin-top: 3px">
                        <label for="exampleInputEmail2">销售价格</label>
                        <select id="dlg_jgdb3" class="form-control" style="width: 100px;" onchange="">
                            <option value="-1" <?php if ($jgdb3 == "-1") echo "selected=\"selected\""; ?>></option>
                            <option value="1" <?php if ($jgdb3 == "1") echo "selected=\"selected\""; ?>>不等于</option>
                            <option value="2" <?php if ($jgdb3 == "2") echo "selected=\"selected\""; ?>>大于</option>
                            <option value="3" <?php if ($jgdb3 == "3") echo "selected=\"selected\""; ?>>小于</option>
                        </select>
                        <label for="exampleInputEmail2">供应价格</label>
                    </div>
                    <br>
                    <div class="form-group" style=" margin-top: 5px">
                        <label for="exampleInputEmail2">价格区间：</label>
                        <input type="number" min="0" class="form-control" style="width: 203px;" id="dlg_jsjg_form" placeholder=""
                               value="<?= $jsjg_form ?>">

                        <label for="exampleInputPassword2">To</label>
                        <input type="number" min="0" class="form-control" style="width: 203px;" id="dlg_jsjg_to"
                               placeholder=""
                               value="<?= $jsjg_to ?>">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="filter(2)"><i class="fa fa-search"></i> 搜索
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-remove"></i> 取消
                </button>
            </div>
        </div>
    </div>
</div>
<!-- Modal GoodsHtml-->
<div class="modal fade" id="myModalHtmlDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">网页详情</h4>
            </div>
            <div id="htmldetail" class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-remove"></i> 关闭
                </button>
            </div>
        </div>
    </div>
</div>
<!-- Modal GoodsDetail-->
<div class="modal fade" id="myModalGoodsDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">商品详情查看</h4>
            </div>
            <div id="goodsdetail" class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-remove"></i> 关闭
                </button>
            </div>
        </div>
    </div>
</div>

<!-- Modal GoodsDetail Edit-->
<div class="modal fade" id="myModalGoodsDetailEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">商品详情编辑</h4>
            </div>
            <div id="goodsdetailedit" class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="goodsEditSave()"><i class="fa fa-save"></i> 保存
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-remove"></i> 关闭
                </button>
            </div>
        </div>
    </div>
</div>

<!-- institution goods import-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="myModalInstGoodsImport" class="modal fade">
    <div class="modal-dialog modal-full">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">机构商品池-导入</h4>
            </div>
            <div id="instGoodsImport" class="modal-body">
                <div class="form-inline">
                    <div class="pull-left">
                        <form id="upload_file_submit_form" enctype="multipart/form-data" method="post"
                              action="import-institution-goods" target="upload_exec_target">
                            <div class="form-group">
                                <input id="upload_file" name="file" type="file" onchange="importFile();"/>
                                <input id="upload_institution_code" name="upload_institution_code" type="hidden"/>
                            </div>
                            <div class="form-group">
                                <a id="excel-download" href="<?= $web ?>/templet/机构商品池导入模板.xlsx">
                                    下载excel模板
                                </a>
                            </div>
                        </form>
                        <iframe id="upload_exec_target" name="upload_exec_target" style="display: none;"></iframe>
                    </div>
                </div>
                <div id="import_file_error"></div>
                <!-- body table-->
                <div id="body_table">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover table-condensed" style=" margin-top: 5px">
                            <thead class="nowrap">
                            <tr>
                                <th style="width:10%">商品编码</th>
                                <th style="width:25%">商品名称</th>
                                <th style="width:7%">结算价格</th>
                                <th style="width:7%">销售价格</th>
                                <th style="width:7%">供应价格</th>
                                <th style="width:6%">是否启用</th>
                                <th style="width:6%">是否上架</th>
                                <th style="width:6%">是否新品</th>
                                <th style="width:6%">是否热销</th>
                                <th style="width:6%">是否置顶</th>
                                <th style="width:6%">是否显示</th>
                                <th style="width:8%">
                                    <span class="popovers" data-trigger="hover"
                                          data-placement="left" data-original-title="提示列"
                                          data-content="当导入的表格数据有错误时会出现ERR标记，请点击ERR查看错误提示"><i
                                            class="fa fa-question"></i></span>
                                </th>
                            </tr>
                            </thead>
                            <tbody id="import_goods_list">

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="importConfirm()"><i
                        class="fa fa-ok"></i> 确认导入
                </button>
                <button class="btn btn-primary" data-dismiss="modal"><i class="fa fa-remove"></i> 关闭</button>
            </div>
        </div>
    </div>
</div>


<!-- 下级机构选择列表-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="modalChildInstList" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <input type="hidden" id="updateChild_SuperInstCode" value="" readonly>
                <h4 class="modal-title">下级机构选择</h4>
            </div>
            <div id="childInstList" class="modal-body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="confUpdateChildData()"><i class="fa fa-save"></i>
                    确定
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-remove"></i> 取消
                </button>
            </div>
        </div>
    </div>
</div>


<!--上下架确认对话框-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="shelveModal" class="modal fade">
    <div class="modal-dialog modal-sms">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">确认操作？</h4>
                <input type="hidden" id="shelve_inst_code" class="form-control" value="">
                <input type="hidden" id="shelve_is_shelved" class="form-control" value="">
            </div>
            <div class="modal-body" id="shelve_modal_body" align="center">
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" onclick="confShelve()"><i class="fa fa-ok"></i> 确认</button>
                <button class="btn btn-primary" onclick="cancShelve()"><i class="fa fa-remove"></i> 取消</button>
            </div>
        </div>
    </div>
</div>


<!--启禁用确认对话框-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="enabledModal" class="modal fade">
    <div class="modal-dialog modal-sms">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">确认操作？</h4>
                <input type="hidden" id="enabled_inst_code" class="form-control" value="">
                <input type="hidden" id="enabled_is_enabled" class="form-control" value="">
            </div>
            <div class="modal-body" id="enabled_modal_body" align="center">
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" onclick="confEnabled()"><i class="fa fa-ok"></i> 确认</button>
                <button class="btn btn-primary" onclick="cancEnabled()"><i class="fa fa-remove"></i> 取消</button>
            </div>
        </div>
    </div>
</div>

<!--提示对话框-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="hintMessageModal" class="modal fade">
    <div class="modal-dialog modal-sms">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">消息</h4>
            </div>
            <div class="modal-body" id="hint_message" align="center">
            </div>
        </div>
    </div>
</div>

<!--错误对话框-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="errMessageModal" class="modal fade">
    <div class="modal-dialog modal-sms">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">错误</h4>
            </div>
            <div class="modal-body" id="err_message">
            </div>
        </div>
    </div>
</div>